package com.zy.springcloud.Controller;

import com.zy.springcloud.entities.CommonResult;
import com.zy.springcloud.entities.Payment;
import com.zy.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/8/6 9:59
 */
@RestController
@Slf4j
public class PaymentController {


    @Autowired
    private PaymentService paymentService;


    @PostMapping( value = "/payment/save")
    public CommonResult save(Payment payment){
        int result = paymentService.save(payment);
        log.info("****save结果="+result);
        if ( result > 0 ){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(444,"插入失败");
        }

    }

    @GetMapping( value = "/payment/get/{id}")
    public CommonResult select(@PathVariable("id") Long id){

        Payment result = paymentService.select(id);
        log.info("****select结果="+result);
        if ( result != null ){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(444,"插入失败");
        }

    }

}
